<!doctype html>
<html lang="en">
	<head>
		<title>three.js canvas - performance</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<script src="../build/Three.js"></script>

		<script src="js/Stats.js"></script>

		<script>

			var container, stats;

			var camera, scene, renderer;

			var sphere, plane;

			var targetRotation = 0;
			var targetRotationOnMouseDown = 0;

			var mouseX = 0;
			var mouseXOnMouseDown = 0;

			var windowHalfX = window.innerWidth / 2;
			var windowHalfY = window.innerHeight / 2;

			init();
			animate();

			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
				camera.position.set( 0, 1000, 1000 );

				scene = new THREE.Scene();

				scene.add( camera );

				// Grid

				var geometry = new THREE.Geometry();
				geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( - 500, 0, 0 ) ) );
				geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 500, 0, 0 ) ) );

				var material = new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.5 } );

				for ( var i = 0; i <= 10; i ++ ) {

					var line = new THREE.Line( geometry, material );
					line.position.z = ( i * 100 ) - 500;
					scene.add( line );

					var line = new THREE.Line( geometry, material );
					line.position.x = ( i * 100 ) - 500;
					line.rotation.y = 90 * Math.PI / 180;
					scene.add( line );

				}

				// Spheres

				geometry = new THREE.SphereGeometry( 100, 26, 18 );
				material = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, overdraw: true } );

				for ( var i = 0; i < 20; i ++ ) {

					sphere = new THREE.Mesh( geometry, material );

					sphere.position.x = ( i % 5 ) * 200 - 400;
					sphere.position.z = Math.floor( i / 5 ) * 200 - 400;

					scene.add( sphere );

				}

				// Lights

				var ambientLight = new THREE.AmbientLight( Math.random() * 0x202020 );
				scene.add( ambientLight );

				var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
				directionalLight.position.x = 0;
				directionalLight.position.y = 1;
				directionalLight.position.z = 0;
				scene.add( directionalLight );

				var pointLight = new THREE.PointLight( 0xff0000, 1, 500 );
				scene.add( pointLight );

				renderer = new THREE.CanvasRenderer();
				renderer.setSize( window.innerWidth, window.innerHeight );

				container.appendChild( renderer.domElement );

				stats = new Stats();
				stats.domElement.style.position = 'absolute';
				stats.domElement.style.top = '0px';
				container.appendChild(stats.domElement);

			}

			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {

				camera.lookAt( scene.position );

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>
